<?php
require $this->__RAD__ . 'component/global/head.php';
?>

<?php
require $this->__RAD__ . 'component/global/nav.php';
?>
	<!-- 内容 -->
	<div class="wrap">
		<div class="banner">
			<img src="<?= $this->__STATIC__ ?>images/contact/banner.jpg">
		</div>
		<div class="allTitle">
			<div class="width">
                <?php
                require $this->__RAD__ . 'component/global/product_center.php';
                ?>
			</div>
		</div>
		<div class="messages">
			<div class="page1">
				<div class="width">
					<div class="contain">
						<div class="title">
							<p>
								在线留言
							</p>
						</div>
						<div class="cen clearboth">
                            <?= $this->substance ?>
							<div class="forms">
                                <form id="forms" method="post">
                                    <input type="text" placeholder="* 公司名称" class="company_name" name="company_name">
                                    <input type="text" placeholder="联络地址" class="address"  name="address">
                                    <input type="text" placeholder="* 联络人" class="people"  name="people">
                                    <input type="text" placeholder="* Email" class="mail"  name="mail">
                                    <input type="text" placeholder="* 联络电话" class="mobile"  name="mobile">
                                    <input type="text" placeholder="传真" class="fax"  name="fax">
                                    <textarea placeholder="* 内容" class="content"  name="content"></textarea>
                                </form>
							</div>
						</div>
						<div class="bot">
							<a href="javascript:;" id="form_click">
								提交
							</a>
							<span>
								“ * ” 字号字段必须填写
							</span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

    <!-- 右侧 -->
    <?php
    require $this->__RAD__ . 'component/global/right.php';
    ?>

    <?php
    require $this->__RAD__ . 'component/global/footer.php';
    ?>

<script>
    $(function(){
        var click_status = 0;
        $("#form_click").click(function(){
            var data = {};
            if (click_status == 1) {
                return false;
            }
            var company_name    =   $("#forms .company_name").val();
            var address         =   $("#forms .address").val();
            var people          =   $("#forms .people").val();
            var mail            =   $("#forms .mail").val();
            var mobile          =   $("#forms .mobile").val();
            var fax             =   $("#forms .fax").val();
            var content         =   $("#forms .content").val();
            var status              =   0;
            if ($.trim(company_name) == "") {
                $("#forms .company_name").css('border','1px solid red');
                status  =   1;
            }
            if ($.trim(people) == "") {
                $("#forms .people").css('border','1px solid red');
                status  =   1;
            }
            if ($.trim(mail) == "") {
                $("#forms .mail").css('border','1px solid red');
                status  =   1;
            }
            if(!mail.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)){
                $("#forms .mail").css('border','1px solid red');
                status  =   1;
            }
            if ($.trim(mobile) == "") {
                $("#forms .mobile").css('border','1px solid red');
                status  =   1;
            }
            var reg = /^1[34578]\d{9}$/;
            if (!reg.test(mobile)){
                $("#forms .mobile").css('border','1px solid red');
                status  =   1;
            }
            if ($.trim(content) == "") {
                $("#forms .content").css('border','1px solid red');
                status  =   1;
            }
            if (status == 1) return;

            $.post('/api/saveForm',
                {
                    company_name:   company_name,
                    address     :   address,
                    people      :   people,
                    mail        :   mail,
                    mobile      :   mobile,
                    fax         :   fax,
                    content     :   content
                },
                function (data) {
                    click_status = 1;
                    switch (data.errcode) {
                        case 0 :
                            alert("留言成功！");
                            $("#forms .company_name, #forms .address, #forms .people").val("");
                            $("#forms .mail,#forms .mobile,#forms .content,#forms .fax").val("");
                            window.location.reload();
                            break;
                        default :
                            alert("网络繁忙，请稍后再试...");
                            break;
                    }
                }, 'json'
            );

        })

        $("#forms .company_name,#forms .people,#forms .mail,#forms .mobile,#forms .content ").click(function(){
            $(this).css('border','1px solid #eaeaea');
        })

    })
</script>